﻿namespace PageTypeBuilderUI
{
    using System.IO;
    using System.Reflection;
    using System.Web.Hosting;

    internal class ResourceVirtualFile : VirtualFile
    {
        private readonly string _resourceName;
        private readonly bool _physicalResource;
        public ResourceVirtualFile(string virtualPath, string resourceName, bool physicalResource)
            : base(virtualPath)
        {
            _resourceName = resourceName;
            _physicalResource = physicalResource;
        }
        public override Stream Open()
        {
            if (_physicalResource)
                return File.OpenRead(_resourceName);

            return Assembly.GetExecutingAssembly().GetManifestResourceStream(this._resourceName);
        }
    }
}
